package com.ssm.xm.controller.Login;


import com.ssm.xm.model.ThInfo;
import com.ssm.xm.service.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ThInfo thInfo){

        //1.接收数据
        //2.调用业务
        ThInfo thInfo_db = adminService.queryThInfoByThInfo(thInfo);
        System.out.println(thInfo_db);
        if (thInfo_db!=null){
            if(thInfo.getUserNumber().equals(thInfo_db.getUserNumber())&&thInfo.getUserPassowrd().equals(thInfo_db.getUserPassowrd())){
                model.addAttribute("message", "登录成功");
                session = request.getSession();
                session.setAttribute("thInfo_db",thInfo_db);
                //3.返回页面
                return "view/farme/index1";
            }else {
                model.addAttribute("message", "登录失败，请重新登录");
                return "login";
            }
        }else {
            model.addAttribute("message", "登录失败，请重新登录");
            return "login";
        }

    }
}
